// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: fengyang

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::bitget::feed_v1 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class BitgetFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit BitgetFeedProcessor(const std::string& system_name,
                               const coin2::exchange::di::ConstantInjection& ci,
                               const feed::RawParserConfig& config,
                               const MarketExchangeApi& mea)
    : FeedParsingProcessor(
          system_name,
          mea,
          ci, config,
          "cc/coin2/exchange/bitget/feed_v1/schema.json") {
  }

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;

  struct FundingRateUpdate {
    bool funding_time_update;
    bool funding_rate_update;
    FundingRate funding_rate;
    void Clear() {
      funding_time_update = false;
      funding_rate_update = false;
      funding_rate.Clear();
    }
  };

 private:
  FundingRateUpdate* GetFundingRateMutable(const std::string& native_symbol);
  bool TryPublishFundingRate(const std::string& native_symbol, FundingRateUpdate* update);
  std::map<std::string, FundingRateUpdate> symbol2fundingrate_;  // funding rate cache
};

}  // namespace impl
using impl::BitgetFeedProcessor;
}  // namespace coin2::exchange::bitget::feed_v1
